# 数据库配置文件
HOST = 'localhost'
PORT = 3306
USER = 'root'
PASSWORD = '123456'
DB = 'demo01'

import os
# import platform

BASEDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# 本地项目日志路径
CURRENT_LOG_PATH = os.path.join(BASEDIR, 'logs')

# PREFIX = CURRENT_LOG_PATH if platform.system() == 'Windows' else '/opt/logs/python_apps_logs/Business_lsms_sync_service'

# 判断目录是否存在，若不存在则创建
if not os.path.exists(CURRENT_LOG_PATH):
    os.makedirs(CURRENT_LOG_PATH)

# # 日志文件路径
# LOG_PATH_DEBUG = r'%s\debug.log' % CURRENT_LOG_PATH if platform.system(
# ) == 'Windows' else '%s/debug.%s.log' % (CURRENT_LOG_PATH, os.getpid())
# LOG_PATH_INFO = r'%s\info.log' % CURRENT_LOG_PATH if platform.system(
# ) == 'Windows' else '%s/info.%s.log' % (CURRENT_LOG_PATH, os.getpid())
# LOG_PATH_WARN = r'%s\warn.log' % CURRENT_LOG_PATH if platform.system(
# ) == 'Windows' else '%s/warn.%s.log' % (CURRENT_LOG_PATH, os.getpid())
# LOG_PATH_ERROR = r'%s\error.log' % CURRENT_LOG_PATH if platform.system(
# ) == 'Windows' else '%s/error.%s.log' % (CURRENT_LOG_PATH, os.getpid())

# 日志配置
LOGGING_CONFIG = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            # 'format': '[%(asctime)s] %(levelname)s - (%(process)d %(thread)d) - %(module)s.py[line:%(lineno)d] - %(message)s'
            'format': '[%(asctime)s] %(levelname)s - %(module)s.py[line:%(lineno)d] - %(message)s'
        },
    },
    'handlers': {
        'error': {
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'level': 'ERROR',
            'formatter': 'standard',
            'filename': os.path.join(CURRENT_LOG_PATH,'error.log') ,
            'when': 'D',
            'interval': 1
        },
        # 'warn': {
        #     'class': 'logging.handlers.TimedRotatingFileHandler',
        #     'level': 'WARN',
        #     'formatter': 'standard',
        #     'filename': os.path.join(CURRENT_LOG_PATH,'warn.log'),
        #     'when': 'H',
        #     'interval': 1
        # },
        'info': {
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'level': 'INFO',
            'formatter': 'standard',
            'filename': os.path.join(CURRENT_LOG_PATH,'info.log'),
            'when': 'D',
            'interval': 1,
            'encoding':'utf-8'
        },
        # 'debug': {
        #     'class': 'logging.handlers.TimedRotatingFileHandler',
        #     'level': 'DEBUG',
        #     'formatter': 'standard',
        #     'filename': os.path.join(CURRENT_LOG_PATH,'debug.log'),
        #     'when': 'H',
        #     'interval': 1
        # }
    },
    'loggers': {
        'default': {
            # 'handlers': ['debug', 'info', 'warn', 'error'],
            'handlers': ['info', 'error'],
            'level': 'DEBUG',
            'propagate': True
        }
    }
}

if __name__ == '__main__':
    # if not os.path.exists(CURRENT_LOG_PATH):
    #     os.makedirs(CURRENT_LOG_PATH)
    # print(CURRENT_LOG_PATH)
    import logging.config

    logging.config.dictConfig(LOGGING_CONFIG)
    logger = logging.getLogger("default")
    logger.debug('debug message')
    logger.info('info message')
    logger.warning('warning message')
    logger.error('error message')
    logger.critical('critical message')
    print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
